package com.kehutong.flow.admin;

import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;

import com.kehutong.common.DoveClient;
import com.kehutong.common.util.Token;
import com.kehutong.flow.service.FlowRuleService;

@MvcAction
@ReqMapping("/admin/flow/rule")
public class FlowRuleController {

	@Inject
	private JdbcSession jdbcSession;

    @Inject
    private DoveClient doveClient;

    @Inject
    private FlowRuleService flowRuleService;

    @HasPermission("flow:rule:view")
    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {
    	return Result.success(flowRuleService.list(jsonObject));
    }

    @HasPermission("flow:rule:view")
    @ReqMapping("/get")
    public Object get(Token token, String id) {
        return Result.success(flowRuleService.get(token, id));
    }

//    @Bean(newInstance=true, copy=true)
    @HasPermission("flow:rule:edit")
    @ReqMapping("/save")
    public Object save(Token token, JSONObject jsonObject) {
        return flowRuleService.save(token, jsonObject);
    }

//    @Bean(copy=true)
    @HasPermission("flow:rule:edit")
    @ReqMapping("/update")
    public Object update(Token token, JSONObject jsonObject) {
        return flowRuleService.update(token, jsonObject);
    }

    @HasPermission("flow:rule:edit")
    @ReqMapping("/delete")
    public Object delete(String id) {
        return flowRuleService.delete(id);
    }

    @ReqMapping("/enums")
    public Object loadEnums() {
    	return Result.success(flowRuleService.loadEnums());
    }

}
